package com.gene.service.impl;

import com.gene.mapper.UserIncomeMapper;
import com.gene.pojo.UserIncome;
import com.gene.pojo.UserIncomeExample;
import com.gene.service.IUserIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserIncomeServiceImpl implements IUserIncomeService{
    @Autowired
    private UserIncomeMapper userIncomeMapper;

    @Override
    public List<UserIncome> query(UserIncome userIncome) {
        UserIncomeExample example=new UserIncomeExample();
        UserIncomeExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userIncome.getUserId());
        criteria.andModeEqualTo((byte) 1);
        example.setOrderByClause("ctime DESC");
        List<UserIncome> list = userIncomeMapper.selectByExample(example);
        return list;
    }

    @Override
    public boolean add(UserIncome userIncome) {
        userIncome.setCtime(new Date());
        int a=userIncomeMapper.insert(userIncome);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(UserIncome userIncome) {
        int a=userIncomeMapper.updateByPrimaryKeySelective(userIncome);
        if(a==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(UserIncome userIncome) {
        int a=userIncomeMapper.deleteByPrimaryKey(userIncome.getIncomeId());
        if(a==1){
            return true;
        }
        return false;
    }
}
